//
//  HotCountryTableViewCell.m
//  Journey
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotCountryTableViewCell.h"
#import "HotCountryCollectionViewCell.h"
@interface HotCountryTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,strong)BaseCollectionView *myCollectionView;
@end
@implementation HotCountryTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createHotCountry];
    }
    return self;
}

-(void)createHotCountry{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 2 + 20, 250 * WIDTHC);
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.minimumLineSpacing = 20;
    
    self.myCollectionView = [[BaseCollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
    self.myCollectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFFFF,0x363636);
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.myCollectionView registerClass:[HotCountryCollectionViewCell class] forCellWithReuseIdentifier:@"hotcountryCell"];
    //取消左右滑动
    self.myCollectionView.scrollEnabled = NO;
    [self.contentView addSubview:self.myCollectionView];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.myCollectionView.frame = CGRectMake(15 * WIDTHC, 0, self.contentView.frame.size.width - 30, self.contentView.frame.size.height - 20);
}

//cell数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HotCountryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hotcountryCell" forIndexPath:indexPath];
    cell.hotCountry = [self.dataArray objectAtIndex:indexPath.row];
  //  cell.backgroundColor = [UIColor grayColor];
    return cell;
    
}

-(void)setDestinationArray:(NSMutableArray *)destinationArray{
    _destinationArray = destinationArray;
    self.dataArray = [NSMutableArray array];
    self.dataArray = [NSMutableArray arrayWithArray:_destinationArray];
    [self.myCollectionView reloadData];
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    hotCountryModel *model = [self.dataArray objectAtIndex:indexPath.row];
    NSNumber *countryId = model.countryId;
    
    self.hotCountryBlock(countryId);
}


@end
